package com.feng.annotation.dao;

import com.feng.annotation.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author Lee
 * @date 2019/3/9
 */
@Repository
public class UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void insertUser(User user) throws Exception {
        String sql = "INSERT INTO tbl_user(username,age) VALUES('" + user.getUsername() + "'," + user.getAge() + ")";
        try {
            jdbcTemplate.update(sql);
        } catch (Exception e) {
            throw new Exception("保存用户异常");
        }
    }

}
